package com.example.test.Controller;

import com.example.test.Bean.UserBean;
import com.example.test.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Resource
    UserService userService;

    @RequestMapping("/login")
    public String show(){
        return "login";
    }

    @RequestMapping(value = "/loginIn",method = RequestMethod.POST)
    public String login(String name, String Password, HttpSession session){
        UserBean userBean = userService.loginIn(name, Password);
        if(userBean!=null){
            session.setAttribute("user",userBean);
            return "success";
        }
        else{
            return "error";
        }
    }
}
